//另一颗树的子树
//Tree m
//Subtree n
//时间复杂度 m*n
class Solution2 {
    public boolean isSubtree(TreeNode root, TreeNode subRoot) {
        if(root == null || subRoot == null)
        {
            return false;
        }
        //1.是不是和根节点相同
        if(isSameTree(root,subRoot))
        {
            return true;
        }
        //2.判断是不是root的左子树
        if(isSubtree(root.left,subRoot) )
        {
            return true;
        }
        //3.右子树
        if(isSubtree(root.right,subRoot))
        {
            return true;
        }
        //返回
        return false;
    }
     public boolean isSameTree(TreeNode p, TreeNode q) {
        if((p != null && q == null) || (p == null && q != null)){
            return false;
        }
        if(p == null && q == null){
            return true;
        }
        if(p.val != q.val){
            return false;
        }
       return isSameTree(p.left,q.left) && isSameTree (p.right,q.right);
    }
}